#ifndef SERIALSOCKET_H
#define SERIALSOCKET_H

#include <QWidget>
#include <QtNetwork/QUdpSocket>
#include <QtNetwork/QTcpSocket>
#include <QtNetwork/QTcpServer>
#include <QtSerialPort/QSerialPort>
#include <QtSerialPort/QSerialPortInfo>
#include <QMessageBox>
#include <iostream>
using namespace std;

namespace Ui {
class SerialSocket;
}

class SerialSocket : public QWidget
{
    Q_OBJECT

public:
    explicit SerialSocket(QWidget *parent = 0);
    ~SerialSocket();
    enum ComType{NoType,Serial,Socket};

private:
    Ui::SerialSocket *ui;
    ComType type;
    bool isValic;
    int socketType;
    QSerialPort *serialport;
    QUdpSocket  *udpSocket;
    QTcpSocket  *tcpSocket;
    QTcpServer  *tcpServer;
    QHostAddress ipAddr;
    quint16 ipSrcPort,ipDetPort;
    QByteArray dataRx,dataTx;

signals:
    void ReadyRecv(QByteArray &data);

private slots:
    void RecvPackets(void);
    void SendPackets(QByteArray &data);
    void ConfigSocket(void);
    void NewConnect(void);
    void DisConnect(void);
    void serialOpen();
    void serialBaud();
    void serialScan();
    void serialError();
};

#endif // SERIALSOCKET_H
